package org.jeecg.qis.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.qis.entity.QisProcdetailValue;
import org.jeecg.qis.mapper.QisProcdetailValueMapper;
import org.jeecg.qis.service.IQisProcdetailValueService;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 过程检验单明细表
 * @Author: shaolong
 * @Date: 2022-10-11
 * @Version: V1.0
 */
@Service
public class QisProcdetailValueServiceImpl extends ServiceImpl<QisProcdetailValueMapper, QisProcdetailValue> implements IQisProcdetailValueService {

    @Autowired
    private QisProcdetailValueMapper qisProcdetailValueMapper;

    @Override
    public List<Map<String, String>> queryDetailColumnList(Map<String, String> param) {
        return this.baseMapper.queryDetailColumnList(param);
    }

    @Override
    public List<Map<String, Object>> queryDetailList(Map<String, String> param) {
        //1.先找出此检验单本工序的所有主序列号条目
        List<Map<String, Object>> maps = qisProcdetailValueMapper.queryUNITSNList(param);
        //2.根据对应序列号条目找出子条目并形成对象
        List<Map<String, Object>> list = new ArrayList<>();
        maps.forEach(item -> {
            HashMap<String, Object> map = new HashMap<>();
            String headid = item.get("headid").toString();
            map.put("name", item.get("unitsn"));
            List<Map<String, String>> maps1 = qisProcdetailValueMapper.queryDetailList(headid);
            maps1.forEach(item2 -> {
                map.put(item2.get("title"), item2.get("val"));
            });
            list.add(map);
        });
        return list;
    }

    @Override
    public List<QisProcdetailValue> selectByMainId(String mainId) {
        return qisProcdetailValueMapper.selectByMainId(mainId);
    }

    @Override
    public Result<String> edit(QisProcdetailValue qisProcdetailValue) {
        LambdaUpdateWrapper<QisProcdetailValue> eq = new LambdaUpdateWrapper<QisProcdetailValue>();
        //eq.eq(QisProcdetailValue::getRecId, qisMatdetailCfg.getRecId());
        boolean update = update(qisProcdetailValue, eq);
        return update ? Result.ok("修改成功!") : Result.error("修改失败!");
    }
}
